package com.ecommerce.utils

import com.typesafe.config.{Config, ConfigFactory}
import java.io.InputStream

object ConfigLoader {
  private val mainConfig: Config = ConfigFactory.load("application.conf")

  private val localConfig: Config = try {
    val resourceStream: InputStream = getClass.getClassLoader.getResourceAsStream("local-application.conf")
    if (resourceStream != null) {
      ConfigFactory.parseResources("local-application.conf")
    } else {
      ConfigFactory.empty()
    }
  } catch {
    case ex: Exception =>
      println(s"加载本地配置文件出错: ${ex.getMessage}")
      ConfigFactory.empty()
  }

  //  添加resolve()解析变量引用
  def loadConfig: Config = localConfig.withFallback(mainConfig).resolve()
}